package com.logic.saas.util.interceptor;

import java.util.Hashtable;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;

public class Locales {
    
    private static Map<String, Locale> locales;
    
    static{
        locales = new Hashtable<String, Locale>(16);
        
        locales.put(getResourceBundle(Locale.US).getString("ui_language"), Locale.US);
        locales.put(getResourceBundle(Locale.CHINA).getString("ui_language"), Locale.CHINA);
    }
    
    private static Map<String, Integer> langint;
    
    static{
        //0(zh_cn)|1(en_us)|2(en_en)|3(zh_tw)|4(jp)
        langint = new Hashtable<String, Integer>(16);
        langint.put("zh_CN", 0);
        langint.put("en_US", 1);
        
        langint.put("Chinese", 0);
        langint.put("English", 1);
    }
    
	public static Locale getLocale(String language) {
	    return locales.get(language);
	}
	
    public static Integer getLangint(String language) {
        return langint.get(language);
    }
    
    public Map<String, Locale> getLocales(){
        return locales;
    }
    /**
     * get resources from resource file, the default path is "resource" 
     * @param key  
     * @param locale :current locale
     * @return
     */
    public static ResourceBundle getResourceBundle(Locale locale){
    	Locale current=(locale==null? Locale.ENGLISH:locale);
    	ResourceBundle bundle=null;
		bundle=ResourceBundle.getBundle ("resource", current);
		
		return bundle;
    }
}
